﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace NetQueryLib
{
	public static class NetQueryExtensions
	{
		public static IEnumerable<NetQuery> Find(this IEnumerable<NetQuery> elements, string selector)
		{
			foreach (var element in elements)
				foreach (var result in element.Find(selector))
					yield return result;
		}

		public static string Text(this IEnumerable<NetQuery> elements)
		{
			var els = elements.Select(el => el.Text()).ToArray();

			return String.Join(",", els);
		}

		public static string Html(this IEnumerable<NetQuery> elements)
		{
			var els = elements.Select(el => el.Html()).ToArray();

			return String.Join("\n", els);
		}

		public static string Attr(this IEnumerable<NetQuery> elements, string attributeName)
		{
			var els = elements.Select(el => el.Attr(attributeName)).ToArray();

			return String.Join(",", els);
		}
	}	
}